import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '../view/Login/login.vue'
import Home from '../view/Home/Home.vue'
import User from '../view/User/user.vue'
import HotProjects from '../view/HotProjects/HotProjects.vue'
import MyProject from '../view/MyProject/MyProject.vue'
import MyMessage from '../view/MyMessage/MyMessage.vue'
import MyTracking from '../view/MyTracking/MyTracking.vue'
import MySecurity from "../view/MySecurity/MySecurity.vue"

const routes = [
    {
      path: '/',
      component: Layout
    },
    {
      path: '/Home',
      component: Home,
    },
    {
        path:"/User",
        component:User
    },
    {
        path:"/HotProjects",
        component:HotProjects
    },
     {
        path:"/MyProject",
        component:MyProject
    },
    {
      path: "/MyMessage",
      component: MyMessage
    },
    {
      path: "/MyTracking",
      component: MyTracking
    },
    {
      path: "/MySecurity",
      component: MySecurity
    }
  ]

const router = createRouter({
  routes,
  history: createWebHashHistory()
})

// 添加全局路由守卫
router.beforeEach((to, from, next) => {
  const isAuthenticated = localStorage.getItem('authToken')
  if (to.meta.requiresAuth && !isAuthenticated) {
    next('/login') 
  } else {
    next() 
  }
})

export default router